package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

public class config extends AppCompatActivity {
    private static final String TAG ="ConfigActivity";
    private float dollar3,euro3,won3;
    EditText dollarText,euroText,wonText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_config);

        Intent intent = getIntent();
        float dollar2 = intent.getFloatExtra("dollar_rate_key",0.0f);
        float euro2 = intent.getFloatExtra("euro_rate_key",0.0f);
        float won2 = intent.getFloatExtra("won_rate_key",0.0f);

        Log.i(TAG,"onCreate：dollar2="+ dollar2);
        Log.i(TAG,"onCreate：euro2="+ euro2);
        Log.i(TAG,"onCreate：won2="+ won2);
        dollarText = (EditText)findViewById(R.id.dollar_rate);
        euroText = (EditText)findViewById(R.id.euro_rate);
        wonText = (EditText)findViewById(R.id.won_rate);//显示数据

        dollarText.setText(String.valueOf(dollar2));
        euroText.setText(String.valueOf(euro2));
        wonText.setText(String.valueOf(won2));//转换字符类型

        dollar3 = Float.parseFloat(dollarText.getText().toString());
        euro3 = Float.parseFloat(euroText.getText().toString());
        won3 = Float.parseFloat(wonText.getText().toString());
        Log.i(TAG, "save: 获取到新的值");
        Log.i(TAG, "save: newDollar=" + dollar3);
        Log.i(TAG, "save: newEuro=" + euro3);
        Log.i(TAG, "save: newWon=" + won3);
    }

        public void skip(View btn){
            dollar3 = Float.parseFloat(dollarText.getText().toString());
            euro3 = Float.parseFloat(euroText.getText().toString());
            won3 = Float.parseFloat(wonText.getText().toString());
            Log.i(TAG, "save: 获取到新的值");
            Log.i(TAG, "save: newDollar=" + dollar3);
            Log.i(TAG, "save: newEuro=" + euro3);
            Log.i(TAG, "save: newWon=" + won3);

            Intent intent = getIntent();
            Bundle bdl = new Bundle();
            bdl.putFloat("key_dollar",dollar3);
            bdl.putFloat("key_euro",euro3);
            bdl.putFloat("key_won",won3);
            intent.putExtras(bdl);
            setResult(2,intent);

            finish();
        }
}